package cn.zhl.different;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.HashSet;
import java.util.Set;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-09-24 12:04
 **/
public class DifferentExcelListener extends AnalysisEventListener<DifferentEo> {

	@Override
	public void invoke(DifferentEo data, AnalysisContext context) {
		if(null == data.getName()){
			return;
		}
//		boolean isEnglish = data.getName().matches("[a-zA-Z]+");
		boolean isEnglish = data.getName().matches("^\\w+$");
		if(!isEnglish){
			return;
		}
		if(!("TRUE".equals(data.getVirtual())||"true".equals(data.getVirtual()))) {
			String sheetName = context.readSheetHolder().getSheetName();
			String tableName = sheetName.split("\\(")[0].trim();
			Set<String> tableSet = FindDifferentBetweenDbAndExcel.map.get(tableName);
			if(null == tableSet){
				tableSet = new HashSet<>();
				FindDifferentBetweenDbAndExcel.map.put(tableName,tableSet);
			}
			tableSet.add(data.getName());
		}
	}

	@Override
	public void doAfterAllAnalysed(AnalysisContext analysisContext) {

	}
}
